var dictMap;
$(function(){
	$.ajax({
		type : "post",
		url : "/sys/dict/getDictData",
		data : {
			},
		dataType : "json",
		async : false,
		success : function(data) {
			if(data.message != null) {
				dictMap = data.message;
			}
		}
	}); 
})

// 单个字典时使用
function getDictLable(dictType, dictValue) {
	return dictMap[dictType][dictValue];
}

// 多个字典时
function getDictLables(dictType, dictValue) {
	var resultStr = "";
	for(var key in dictMap[dictType]) {
		if(dictValue.includes(key)) {
			var conTmp = resultStr == ""?"":",";
			resultStr = resultStr + conTmp + dictMap[dictType][key];
		}
	}
	return resultStr;
}

// input 绑定select 单选
function setDictSelect(id, dictType, defaultValue) {
	var html = "<option value='' >请选择</option>";
	for(var key in dictMap[dictType]) {
		if(defaultValue == key) {
			html = html + "<option selected='selected' value='" + key + "'>" + dictMap[dictType][key] + "</option>" 
		} else {
			html = html + "<option value='" + key + "'>" + dictMap[dictType][key] + "</option>"
		}
	}
	$("#" + id).html(html);
	layui.use(['form'], function(){
	var form = layui.form;
	form.render();
	});
}